# 构建对象对战平台object_play
# 1 英雄一代战机（战斗力60）与敌军战机（战斗力70）对抗。英雄1代战机失败！
# 2 卧薪尝胆，英雄二代战机（战斗力80）出场！，战胜敌军战机！
# 3 对象对战平台object_play, 代码不发生变化的情况下, 完成多次战斗
# 思路分析: 抽象战机类 HeroFighter  AdvHeroFighter；敌机EnemyFighter; 构建对象战斗平台,使用多态实现

class HeroFighter(object):
    def power(self):
        return 60


class AdvHeroFighter(HeroFighter):
    def power(self):
        return 80


class EnemyFighter(object):
    def attack(self):
        return 70


# 搭建一个平台(框架), 让对象唱戏
def object_play(herofighter:HeroFighter, enemyfighter:EnemyFighter):
# def object_play(herofighter, enemyfighter):
    # herofighter.power() 此处发生多态!!!
    # 看面向对象代码要时时刻刻注意什么时候会发生多态
    if herofighter.power() > enemyfighter.attack() :
        print('英雄战机胜利, 敌机失败')
    else:
        print('英雄战机失败, 敌机胜利')


if __name__ == '__main__':
    # 实例化1代战机 2代战机
    myherofighter = HeroFighter()
    myadvherofighter = AdvHeroFighter()
    myenemyfighter = EnemyFighter()

    print('-------------采用多态------------------')
    # 一代战机出场
    object_play(myherofighter, myenemyfighter)

    # 二代战机出场
    object_play(myadvherofighter, myenemyfighter)
    pass


# 若不使用多态
if __name__ == '__main__':
    # 实例化1代战机 2代战机
    myherofighter = HeroFighter()
    myadvherofighter = AdvHeroFighter()
    myenemyfighter = EnemyFighter()

    print('-------------不采用多态,代码繁琐, 可拓展性不好------------------')
    # 不采用多态,代码繁琐, 可拓展性不好
    # 一代战机出场
    if myherofighter.power() > myenemyfighter.attack():
        print('英雄战机胜利, 敌机失败')
    else:
        print('英雄战机失败, 敌机胜利')

    # 二代战机出场
    if myadvherofighter.power() > myenemyfighter.attack():
        print('英雄战机胜利, 敌机失败')
    else:
        print('英雄战机失败, 敌机胜利')
    pass

